<?php
class m_keuangan_donatur_tunggal extends Model{
    function getCountRows($params){
        $where = "";
        if($params['awal'] != "" && $params['akhir']){
            $where .= "where kd.tanggal between '$params[awal]' and '$params[akhir]'";
        }
        if($params['idDonaturTunggal'] != ""){
            $where .= " and kd.id_donatur_tunggal='$params[idDonaturTunggal]'";
        }
        
        $query = $this->db->query("select kd.*,m1.nama as petugas,m2.nama as donatur_tunggal from keuangan_donatur_tunggal kd 
                                  join member m1 on kd.id_petugas = m1.id
                                  join member m2 on kd.id_donatur_tunggal = m2.id $where");
        return $query->num_rows();
    }
    function getListKeuanganDonaturTunggal($offset = NULL,$limit = NULL,$params){
        $where = "";
        if($params['awal'] != "" && $params['akhir']){
            $where .= "where kd.tanggal between '$params[awal]' and '$params[akhir]'";
        }
        if($params['idDonaturTunggal'] != ""){
            $where .= " and kd.id_donatur_tunggal='$params[idDonaturTunggal]'";
        }
        if($offset != NULL || $limit != NULL){
            $limits = "limit $offset,$limit";
        }else $limits = '';
        
        $query = $this->db->query("select kd.*,m1.nama as petugas,m2.nama as donatur_tunggal from keuangan_donatur_tunggal kd 
                                  join member m1 on kd.id_petugas = m1.id
                                  join member m2 on kd.id_donatur_tunggal = m2.id $where order by kd.tanggal desc $limits");
        if($query->num_rows() > 0){
            return $query->result_array();
        }else return array();
    }
    function unapproveKeuanganDonaturTunggal($jenis,$id,$bulan,$tahun,$jumlah){
        if($jenis == 'debet'){
           $updateRekap = $this->db->query("update rekap_keuangan_bulanan set jumlah = (jumlah-$jumlah) where id = '".$bulan.$tahun."'");
        }else if($jenis == 'kredit'){
           $updateRekap = $this->db->query("update rekap_keuangan_bulanan set jumlah = (jumlah+$jumlah) where id = '".$bulan.$tahun."'");
        }
        $query = $this->db->query("update keuangan_donatur_tunggal set status = '0' where id = '$id'");
        if($query) return TRUE;
    }
}
?>
